package www.woniuxy.com.class112.controller;

import cn.hutool.core.bean.BeanUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import www.woniuxy.com.class112.form.AddApplicationForm;
import www.woniuxy.com.class112.param.AddApplicationParam;
import www.woniuxy.com.class112.service.UserIdentityService;
import www.woniuxy.com.class112.util.JwtUtil;
import www.woniuxy.com.class112.util.Result;

import javax.annotation.Resource;

@RestController
@RequestMapping("/userIdentity")
@Api(tags = "申请认证相关接口")
public class UserIdentityController {
    @Resource
    private UserIdentityService userIdentityService;

    @PostMapping("/addApplicationForm")
    @ApiOperation("添加申请认证表")
    public Result addApplicationForm(
            @RequestParam("typeId") Long typeId,
            @RequestParam("unitName") String unitName,
            @RequestParam("direction") String direction,
            @RequestParam("corporation") String corporation,
            @RequestParam("phone") Long phone,
            @RequestParam("identificationNumber") Long identificationNumber,
            @RequestParam("employedPersonnel") Long employedPersonnel,
            @RequestParam("operatingArea") Long operatingArea,
            @RequestParam("businessAddress") String businessAddress,
            @RequestParam("image") MultipartFile image,  // 处理文件上传
            @RequestHeader String token) throws Exception {

        Long userId = JwtUtil.getUserId(token);

        // 手动设置参数
        AddApplicationParam param = new AddApplicationParam();
        param.setTypeId(typeId);
        param.setUnitName(unitName);
        param.setDirection(direction);
        param.setCorporation(corporation);
        param.setPhone(phone);
        param.setIdentificationNumber(identificationNumber);
        param.setEmployedPersonnel(employedPersonnel);
        param.setOperatingArea(operatingArea);
        param.setBusinessAddress(businessAddress);
        param.setImage(image); // 设置上传的文件
        param.setUserId(userId);

        userIdentityService.addApplicationForm(param);
        return Result.success("添加成功", null);
    }

}
